import { Config, Inject, Provide } from '@midwayjs/decorator';
import { BaseService, CoolCommException } from '@cool-midway/core';
import { BizAdListEntity } from '../entity/list';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';

/**
 * 广告app服务
 */
@Provide()
export class BizAdListAppService extends BaseService {
  @InjectEntityModel(BizAdListEntity)
  bizAdListEntity: Repository<BizAdListEntity>;

  async list(query: any, option: any, connectionName?: any): Promise<any> {
    const whereStrs = [];
    for (let key in query) {
      whereStrs.push(`${key} = ${query[key]}`);
    }
    whereStrs.push('status = 1');
    const sqlStr = `
      SELECT list.id,list.kind,list.coverImg,list.title,list.pagePath,list.pageP FROM biz_ad_list AS list
      WHERE ${whereStrs.join(' && ')} 
      ORDER BY id ASC;
    `;

    return await this.nativeQuery(sqlStr);
  }

  async info(id: any, infoIgnoreProperty?: string[]): Promise<any> {
    return await this.bizAdListEntity.findOneBy({ id, status: 1 });
  }
}
